package com.jackie.coupon.customer.dao.converter;

import com.jackie.coupon.customer.api.enumss.CouponStatus;

import javax.persistence.AttributeConverter;

/**
 * CouponStatusConverter
 *
 * 用法:
 * 1、实体类上标注@Convert(XXX.class)
 * 2.编写XXX类，该类实现AttributeConverter类
 * 3、分别写实现的两个方法
 *
 * @author Jackie Hou
 * @date 2023/11/18 23:49
 * @version 1.0
 */
public class CouponStatusConverter implements AttributeConverter<CouponStatus, Integer> {

    @Override
    public Integer convertToDatabaseColumn(CouponStatus couponStatus) {
        return couponStatus.getCode();
    }

    @Override
    public CouponStatus convertToEntityAttribute(Integer code) {
        return CouponStatus.convert(code);
    }
}
